package Noyau;

import java.awt.geom.Point2D;

public abstract class ObjetMobile extends ObjetMetier 
{
	protected ObjetMetier parent = null;
	private double position = 0;
    
    public ObjetMetier getParent()
    {
    	return this.parent;
    }
    
    public void setParent(ObjetMetier value)
    {
    	this.parent = value;
    }
    
    public double getPosition ()  
    {
        return this.position;
    }
    
    public void setPosition(double value)
    {
    	this.position = value;
    }
	
	@Override
	public Point2D getCenter() 
	{
		if (this.parent == null)
		{
			return new Point2D.Double(0, 0);
		}
		
		double parentSize = this.parent.getVisualSize();
		if (parentSize > 0)
		{
			double dist = (parentSize / 2) - (this.position * parentSize);
			
			double rotX = (Math.cos(this.parent.getAngle()) * dist) + this.parent.getCenter().getX();
			double rotY = (Math.sin(this.parent.getAngle()) * dist) + this.parent.getCenter().getY();
			
			return new Point2D.Double(rotX, rotY);
		}
		
		return this.parent.getCenter();
	}

	@Override
	public double getAngle()
	{
		if (this.parent == null)
		{
			return 0;
		}
		
		return this.parent.getAngle();
	}
	
	public abstract double getSize();
}
